CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
CMAKE_POLICY(VERSION 2.8)

ADD_SUBDIRECTORY(cunnproduction)

FIND_PACKAGE(CUDA 5.5 REQUIRED)
FIND_PACKAGE(Torch)

ADD_DEFINITIONS(-std=c++11 -fPIC)

IF(DEFINED Torch_INSTALL_INCLUDE)
  SET(THC_INSTALL_INCLUDE ${Torch_INSTALL_INCLUDE})
  SET(TH_INSTALL_INCLUDE ${Torch_INSTALL_INCLUDE})
  SET(TH_INSTALL_LIB ${Torch_INSTALL_LIB})
  SET(THC_INSTALL_LIB ${Torch_INSTALL_LIB})
  SET(THCUNN_INSTALL_LIB ${Torch_INSTALL_LIB}/lua/5.1)
ENDIF()

INCLUDE_DIRECTORIES(
  ${THC_INSTALL_INCLUDE}/THC
  ${THC_INSTALL_INCLUDE}
  ${TH_INSTALL_INCLUDE}/TH
  ${TH_INSTALL_INCLUDE}
  ${CUDA_INCLUDE_DIRS}
  cunnproduction
)

LINK_DIRECTORIES(
  ${TH_INSTALL_LIB} 
  ${THC_INSTALL_LIB} 
  ${THCUNN_INSTALL_LIB}
)

ADD_LIBRARY(loader_static STATIC src/loader.cpp)
ADD_LIBRARY(wrapper_static STATIC src/wrapper.cpp)

ADD_EXECUTABLE(test_networks src/test.cpp)

IF(WITH_OPENCV)
  ADD_SUBDIRECTORY(opencv)
ENDIF()

TARGET_LINK_LIBRARIES(test_networks cunnproduction_static TH THC loader_static)
TARGET_LINK_LIBRARIES(loader_static TH THC cunnproduction_static)
TARGET_LINK_LIBRARIES(wrapper_static TH THC cunnproduction_static loader_static)
